<template>
  <!-- 修改登录密码 -->
  <view class="header">
    <u-toast ref="uToast" />
    <u-navbar :border-bottom="false" title="修改登录密码" title-size="32" title-width="500"></u-navbar>
    <view class="borders flex flex-ai-c flex-jc-sb plr-10 mt-90">
      <view class="font-30 color-333">
        新 密 码
      </view>
      <view class="mobiwidth">
        <u-input v-model="newpassword" type="password" @input="moblieInput" placeholder='请输入6位密码' maxlength='6' class="inputtext"
          placeholder-style="color: #999999;font-size: 30rpx;" />
      </view>
    </view>
    <view class="borders flex flex-ai-c flex-jc-sb plr-10 mt-40">
      <view class="font-30 color-333">
        再次输入
      </view>
      <view class="mobiwidth">
        <u-input v-model="enteragain" type="password" @input="moblieInput2" placeholder='请再次输入新密码' maxlength='6' class="inputtext"
          placeholder-style="color: #999999;font-size: 30rpx;" />
      </view>
    </view>
    <view v-if="nextstep" class="nextstep" @click="nextstepbtn()">
      保存
    </view>
    <view v-else class="nextstep2" @click="baocun()">
      保存
    </view>
  </view>
</template>

<script>
  import md5 from '@/utils/blueimp-md5.js'
  export default {
    data() {
      return {
        newpassword: '',
        enteragain: '',
        nextstep: false,
      }
    },
    methods: {
      md5,
      goPage(url) {
        uni.navigateTo({
          url: url
        })
      },
      moblieInput(event) {
        if (this.newpassword.length !== 6) {
          this.nextstep = false
        } else if (this.enteragain.length !== 6) {
          this.nextstep = false
        } else {
          this.nextstep = true
        }
      },
      moblieInput2(event) {
        if (this.newpassword.length !== 6) {
          this.nextstep = false
        } else if (this.enteragain.length !== 6) {
          this.nextstep = false
        } else {
          this.nextstep = true
        }
      },
      //保存
      nextstepbtn() {
        if (this.newpassword !== this.enteragain) {
          this.$refs.uToast.show({
            title: '两次输入密码不一致',
            type: 'error',
            icon: false,
          })
          this.newpassword = ''
          this.enteragain = ''
          this.nextstep = false
          return
        } else {
          const md5Pwd = this.md5(this.newpassword)
          this.ChangeMyPassword(md5Pwd)
        }
      },
      //修改我的密码
      async ChangeMyPassword(md5Pwd) {
        try {
          const res = await this.$api.system.ChangeMyPassword({
            password: md5Pwd,
            secondPassword: md5Pwd
          })
          if (res.code === 200) {
            this.$refs.uToast.show({
              title: '修改密码成功',
              type: 'success',
              isTab: true,
              url: '/pages/me/me'
            })
          }
        } catch (err) {}
      },
      baocun() {
        this.$refs.uToast.show({
          title: '请输入6位密码',
          icon: false,
          type: 'warning'
        })

      }
    }
  }
</script>

<style lang="scss" scoped>
  .header {
    background-color: rgb(255, 255, 255);
    height: 100vh;
    padding: 55rpx;

    .borders {
      border-bottom: 1px solid #EEEEEE;

      .mobiwidth {
        width: 480rpx;
      }

      .mobiwidth2 {
        width: 300rpx;
      }

      .getCaptcha {
        width: 170rpx;
        height: 60rpx;
        background: linear-gradient(0deg, #FBD220, #FFE23E);
        border-radius: 30rpx;
        font-size: 26rpx;
        font-family: PingFang SC;
        font-weight: 500;
        color: #333333;
        text-align: center;
        line-height: 60rpx;
      }
    }

    .nextstep {
      height: 88rpx;
      background: linear-gradient(0deg, #FBD220, #FFE23E);
      border-radius: 44rpx;
      font-size: 32rpx;
      font-family: PingFang SC;
      font-weight: 500;
      color: #333333;
      text-align: center;
      line-height: 88rpx;
      margin-top: 216rpx;
    }

    .nextstep2 {
      height: 88rpx;
      background: #EEEEEE;
      border-radius: 44rpx;
      text-align: center;
      line-height: 88rpx;
      margin-top: 216rpx;
    }
  }
</style>
